;;;
;;; RST substitution
;;;

%"[ \t]*"0call%"[ \t]*"1__RST00%2
=
%0rst%1 0x00  ; call __RST00%2

%"[ \t]*"0call%"[ \t]*"1__RST08%2
=
%0rst%1 0x08  ; call __RST08%2

%"[ \t]*"0call%"[ \t]*"1__RST10%2
=
%0rst%1 0x10  ; call __RST10%2

%"[ \t]*"0call%"[ \t]*"1__RST18%2
=
%0rst%1 0x18  ; call __RST18%2

%"[ \t]*"0call%"[ \t]*"1__RST20%2
=
%0rst%1 0x20  ; call __RST20%2

%"[ \t]*"0call%"[ \t]*"1__RST28%2
=
%0rst%1 0x28  ; call __RST28%2

%"[ \t]*"0call%"[ \t]*"1__RST30%2
=
%0rst%1 0x30  ; call __RST30%2

%"[ \t]*"0call%"[ \t]*"1__RST38%2
=
%0rst%1 0x38  ; call __RST38%2

;;
;; section information
;;

	call	_SECTION_SIZE_CODE
=
	EXTERN	__CODE_END_tail
	EXTERN	__CODE_head
	ld	hl,__CODE_END_tail - __CODE_head

	call	_SECTION_SIZE_DATA
=
	EXTERN	__DATA_END_tail
	EXTERN	__DATA_head
	ld	hl,__DATA_END_tail - __DATA_head

	call	_SECTION_SIZE_BSS
=
	EXTERN	__BSS_UNINITIALIZED_head
	EXTERN	__BSS_head
	ld	hl,__BSS_UNINITIALIZED_head - __BSS_head

	call	_SECTION_ORG_%1
=
	EXTERN	__%1_head
	ld	hl,__%1_head

	call	_SECTION_END_%1
=
	EXTERN	__%1_tail
	ld	hl,__%1_tail

	call	_SECTION_SIZE_%1
=
	EXTERN	__%1_size
	ld	hl,__%1_size

;;;
;;; intrinsics
;;;

	call	intrinsic_slp
=
	slp

	call	intrinsic_stub
=


	call	intrinsic_di
=
	di

	call	intrinsic_ei
=
	ei

	call	intrinsic_halt
=
	halt

	call	_intrinsic_label_%1
=
%1:

	call	_intrinsic_load16_%1
=
	ld	hl,(%1)

	call	_intrinsic_store16_address_%1
	call	_intrinsic_store16_value_%2
=
	ld	hl,%2
	ld	(%1),hl

	call	_intrinsic_ldi
=
	pop hl
	pop de

	call	_intrinsic_ldi_num_128
=
	call	l_ldi_128

	call	_intrinsic_ldi_num_256
=
	call	l_ldi_256

	call	_intrinsic_ldi_num_%1
=
	call	l_ldi-(%1*2)

	call	l_ldi%1
	ret
=
	jp	l_ldi%1

	call	_intrinsic_outi_num_128
=
	call	l_outi_128

	call	_intrinsic_outi_num_256
=
	call	l_outi_256

	call	_intrinsic_outi_num_%1
=
	call	l_outi-(%1*2)

	call	l_outi%1
	ret
=
	jp	l_outi%1

	call	_intrinsic_outi_port_%1
=
	ld	c,%1

	call	_intrinsic_outi
=


	call	_intrinsic_ini_num_128
=
	call	l_ini_128

	call	_intrinsic_ini_num_256
=
	call	l_ini_256

	call	_intrinsic_ini_num_512
=
	call	l_ini_512

	call	_intrinsic_ini_num_%1
=
	call	l_ini-(%1*2)

	call	l_ini%1
	ret
=
	jp	l_ini%1

	call	_intrinsic_ini_port_%1
=
	ld	c,%1

	call	_intrinsic_ini
=


	call	intrinsic_reti
=
	reti

	call	intrinsic_retn
=
	retn

	call	intrinsic_im_0
=
	im 0

	call	intrinsic_im_1
=
	im 1

	call	intrinsic_im_2
=
	im 2

	call	intrinsic_nop
=
	nop

	call	intrinsic_exx
=
	exx

	call	intrinsic_ex_de_hl
=
	ex	de,hl

	call	intrinsic_return_bc
=
	ld	l,c
	ld	h,b

	call	intrinsic_return_de
=
	ex	de,hl

	call	intrinsic_swap_endian_16
=
	ld	a,l
	ld	l,h
	ld	h,a

	call	intrinsic_swap_endian_32
=
	ld	a,l
	ld	l,d
	ld	d,a
	ld	a,h
	ld	h,e
	ld	e,a

	call	intrinsic_swap_word_32
=
	ex	de,hl
